Ext.onReady(function () {
	$("ul.service-main-tab >li").on('click', function (e) {
		var $this = $(this);
		$(".content-tabs").css('display', 'none');
		$($this.find('a').attr('href')).css('display', 'block');
	});
	$("#DY_site_name").text(setCurrCity());
	$("#JS_city_current_city").text(setCurrCity());
	ajaxQueryTopHotInfo("01");
});

Ext.onReady(function () {
	drawTourTongji(currCityCode);
})

/**
 * 请求热门top10数据，分类分别加载
 * 
 * @param infoType 需要查询的数据的类型01为游；02为吃；03为住；04为购
 * @returns
 */
function ajaxQueryTopHotInfo(infoType) {
	Ext.Ajax.request({
		url: 'servlet/topHotServlet',
		params: {
			"loc": currCityCode,
			"infoType": infoType
		},
		success: function (response) {
			var jsonText = JSON.parse(response.responseText);
			console.log(jsonText);
			var inTabHtml = ' ';
			if ("01" == infoType) {// 景点游数据
				var json01 = jsonText.spotAvgRatingQuery;
				var json02 = jsonText.spotRatingCountQuery;
				var tab1 = document.getElementById("tagsList");
				inTabHtml = ' ';
				for (var t = 0; t < json01.length; t++) {
					var lineHtml = "<span><a href=" + json01[t].spotUrl + "><font color='yellow'>" + json01[t].spotName
							+ "</font></a></span>";
					inTabHtml = inTabHtml + lineHtml;
				}
				tab1.innerHTML = inTabHtml;

				drawCloud('tagsList');
				var tab790 = document.getElementById("wz");
				inTabHtml = '';
				for (var t = 0; t < json01.length; t++) {
					var lineHtml = '<li><a href=' + json01[t].spotUrl + '><font size="4">' + json01[t].spotName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab790.innerHTML = inTabHtml;
				var tab2 = document.getElementById("tagsList1");
				inTabHtml = '';
				for (var t = 0; t < json02.length; t++) {
					var lineHtml = '<span><a href=' + json02[t].spotUrl + '><font color="red">' + json02[t].spotName
							+ '</font></a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab2.innerHTML = inTabHtml;
				drawCloud('tagsList1');

				var tab791 = document.getElementById("wz1");
				inTabHtml = '';
				for (var t = 0; t < json02.length; t++) {
					var lineHtml = '<li><a href=' + json02[t].spotUrl + '><font size="4">' + json02[t].spotName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab791.innerHTML = inTabHtml;
			} else if ("02" == infoType) {
				var json11 = jsonText.shopTasteQuery;
				var json12 = jsonText.shopEnvironmentQuery;
				var json13 = jsonText.shopServiceQuery;
				var tab11 = document.getElementById("tagsList2");
				inTabHtml = '';
				for (var t = 0; t < json11.length; t++) {
					var lineHtml = '<span><a href=' + json11[t].shopUrl + '><font color="yellow">' + json11[t].shopName
							+ '</font></a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab11.innerHTML = inTabHtml;
				drawCloud('tagsList2');

				var tab792 = document.getElementById("wz2");
				inTabHtml = '';
				for (var t = 0; t < json11.length; t++) {
					var lineHtml = '<li><a href=' + json11[t].shopUrl + '><font size="4">' + json11[t].shopName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab792.innerHTML = inTabHtml;

				var tab12 = document.getElementById("tagsList3");
				inTabHtml = '';
				for (var t = 0; t < json12.length; t++) {
					var lineHtml = '<span><a href=' + json12[t].shopUrl + '><font color="yellow">' + json12[t].shopName
							+ '</font></a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab12.innerHTML = inTabHtml;
				drawCloud('tagsList3');

				var tab793 = document.getElementById("wz3");
				inTabHtml = '';
				for (var t = 0; t < json12.length; t++) {
					var lineHtml = '<li><a href=' + json12[t].shopUrl + '><font size="4">' + json12[t].shopName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab793.innerHTML = inTabHtml;
				var tab13 = document.getElementById("tagsList4");
				inTabHtml = '';
				for (var t = 0; t < json13.length; t++) {
					var lineHtml = '<span><a href=' + json13[t].shopUrl + '><font color="red">' + json13[t].shopName
							+ '</a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab13.innerHTML = inTabHtml;
				drawCloud('tagsList4');

				var tab794 = document.getElementById("wz4");
				inTabHtml = '';
				for (var t = 0; t < json13.length; t++) {
					var lineHtml = '<li><a href=' + json13[t].shopUrl + '><font size="4">' + json13[t].shopName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab794.innerHTML = inTabHtml;
			} else if ("03" == infoType) {
				var json21 = jsonText.commentPointQuery;
				var json22 = jsonText.commentScoreQuery;
				var json23 = jsonText.commentCountQuery;
				var tab21 = document.getElementById("tagsList5");
				inTabHtml = '';
				for (var t = 0; t < json21.length; t++) {
					var lineHtml = '<span><a href=' + json21[t].hotelUrl + '><font color="red">' + json21[t].hotelName
							+ '</a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab21.innerHTML = inTabHtml;
				drawCloud('tagsList5');
				var tab795 = document.getElementById("wz5");
				inTabHtml = '';
				for (var t = 0; t < json21.length; t++) {
					var lineHtml = '<li><a href=' + json21[t].hotelUrl + '><font size="4">' + json21[t].hotelName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab795.innerHTML = inTabHtml;

				var tab22 = document.getElementById("tagsList6");
				inTabHtml = '';
				for (var t = 0; t < json22.length; t++) {
					var lineHtml = '<span><a href=' + json22[t].hotelUrl + '><font color="red">' + json22[t].hotelName
							+ '</a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab22.innerHTML = inTabHtml;
				drawCloud('tagsList6');

				var tab796 = document.getElementById("wz6");
				inTabHtml = '';
				for (var t = 0; t < json22.length; t++) {
					var lineHtml = '<li><a href=' + json22[t].hotelUrl + '><font size="4">' + json22[t].hotelName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab796.innerHTML = inTabHtml;

				var tab23 = document.getElementById("tagsList7");
				inTabHtml = '';
				for (var t = 0; t < json23.length; t++) {
					var lineHtml = '<span><a href=' + json23[t].hotelUrl + '><font color="red">' + json23[t].hotelName
							+ '</a></span>';
					inTabHtml = inTabHtml + lineHtml;
				}

				tab23.innerHTML = inTabHtml;
				drawCloud('tagsList7');

				var tab797 = document.getElementById("wz7");
				inTabHtml = '';
				for (var t = 0; t < json23.length; t++) {
					var lineHtml = '<li><a href=' + json23[t].hotelUrl + '><font size="4">' + json23[t].hotelName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab797.innerHTML = inTabHtml;
			} else {
				var json31 = jsonText.itemSaleQuery;
				var json32 = jsonText.itemRateNumQuery;
				var tab31 = document.getElementById("tagsList8");
				inTabHtml = '';
				for (var t = 0; t < json31.length; t++) {
					var lineHtml = '<a href=' + json31[t].itemUrl + ' class="tagc1">' + json31[t].itemName + '</a>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab31.innerHTML = inTabHtml;
				drawsx('tagsList8');

				var tab798 = document.getElementById("wz8");
				inTabHtml = '';
				for (var t = 0; t < 10; t++) {
					var lineHtml = '<li><a href=' + json31[t].itemUrl + '><font size="4">' + json31[t].itemName
							+ '</font></a></li>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab798.innerHTML = inTabHtml;
				var tab32 = document.getElementById("tagsList9");
				inTabHtml = '';

				for (var t = 0; t < json32.length; t++) {
					var lineHtml = '<a href=' + json32[t].itemUrl + ' class="tagc1">' + json32[t].itemName + '</a>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab32.innerHTML = inTabHtml;
				drawsx('tagsList9');
				var tab799 = document.getElementById("wz9");
				inTabHtml = '';
				for (var t = 0; t < 10; t++) {
					var lineHtml = '<li><a href=' + json32[t].itemUrl + '><font size="4">' + json32[t].itemName
							+ '</font></a><li>';
					inTabHtml = inTabHtml + lineHtml;
				}
				tab799.innerHTML = inTabHtml;
			}
		},
		failure: function (response) {
			console.log("0000" + response.responseText);
		}
	});
}

function submitJfreeGuilinTourForm() {
	var myForm = document.forms['ZF_form'];
	var Type = myForm.elements['Type'].value;
	var spot = myForm.elements['spot'].value;
	var zf = myForm.elements['zf'].value;
	var daytime = myForm.elements['daytime'].value;
	var ym = myForm.elements['ym'].value;
	var type = myForm.elements['type'].value;
	var year1 = myForm.elements['year1'].value;
	var year2 = myForm.elements['year2'].value;
	var year3 = myForm.elements['year3'].value;
    var loc=currCityCode;
	var requestUrl = "JfreeGuilinTour?Type=" + Type + "&spot=" + spot + "&zf=" + zf + "&daytime=" + daytime + "&ym="
			+ ym + "&year1=" + year1 + "&year2=" + year2 + "&year3=" + year3 + "&type=" + type + "&loc=" + currCityCode;
	if ('04' == zf) {
		var popWindow = new Ext.Window({
			layout: 'fit',
			width: 430,
			height: 340,
			title: 'popWindow',
			html: "<img src='" + requestUrl + "'></img>"
		});
		popWindow.show();
	} else {
		Ext.Ajax.request({
			url: 'JfreeGuilinTour',
			method: 'get',
			form: 'ZF_form',
			success: function (response, options) {
				var popWindow = new Ext.Window({
					width: 400,
					height: 300,
					title: 'popWindow',
					html: response.responseText
				});
				popWindow.show();
			},
			failure: function (response, options) {
				Ext.Msg.alert('fail:手写中文2' + response.responseText);
			}
		});
	}
}

function submitJfreeTourForm() {
	var myForm = document.forms['form_you'];
	var Type = myForm.elements['Type'].value;
	var spot = myForm.elements['spot'].value;
	var zf = myForm.elements['zf'].value;
	var daytime = myForm.elements['daytime'].value;
	var ym = myForm.elements['ym'].value;
	var type = myForm.elements['type'].value;
	var year1 = myForm.elements['year1'].value;
	var year2 = myForm.elements['year2'].value;
	var year3 = myForm.elements['year3'].value;

	var requestUrl = "JfreeTour?Type=" + Type + "&spot=" + spot + "&zf=" + zf + "&daytime=" + daytime + "&ym=" + ym
			+ "&year1=" + year1 + "&year2=" + year2 + "&year3=" + year3 + "&type=" + type;
	if ('04' == zf) {
		var popWindow = new Ext.Window({
			layout: 'fit',
			width: 430,
			height: 340,
			title: 'popWindow',
			html: "<img src='" + requestUrl + "'></img>"
		});
		popWindow.show();
	} else {
		Ext.Ajax.request({
			url: 'JfreeTour',
			method: 'get',
			form: 'form_you',
			success: function (response, options) {
				var popWindow = new Ext.Window({
					width: 400,
					height: 300,
					title: 'popWindow',
					html: response.responseText
				});
				popWindow.show();
			},
			failure: function (response, options) {
				Ext.Msg.alert('fail:手写中文2' + response.responseText);
			}
		});
	}
}

function moreSpotClick() {
	var columns = [ {
		header: '景点编号',
		dataIndex: 'spotId'
	}, {
		header: '景点名称',
		dataIndex: 'spotName'
	}, {
		header: '景点综合评分',
		dataIndex: 'spotAvgRating'
	}, {
		header: '景点总评论数',
		dataIndex: 'spotRatingCount'
	} ];

	var store = new Ext.data.Store({
		proxy: {
			type: 'ajax',
			url: 'servlet/moreDataServlet?dataClass=01',
			reader: {
				type: 'json',
				totalProperty: 'totalProperty',
				root: 'root',
				idProperty: 'spotId'
			}
		},
		fields: [ {
			name: 'spotId'
		}, {
			name: 'spotName'
		}, {
			name: 'spotAvgRating'
		}, {
			name: 'spotRatingCount'
		} ]
	});

	var grid = new Ext.grid.GridPanel({
		autoHeight: true,
		store: store,
		autoHeight: true,
		columns: columns,
		bbar: new Ext.PagingToolbar({
			pageSize: 10,
			store: store,
			displayInfo: true,
			displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			emptyMsg: "没有记录"
		})
	});
	store.load();

	var popWindow = new Ext.Window({
		width: 800,
		height: 600,
		title: 'popWindow',
		items: [ grid ]
	});
	popWindow.show();
}

function setCurrCity() {
	if ("0771" == currCityCode) {
		return '南宁';
	} else {
		return '桂林';
	}
}
var sts = station_names.split('@');
function search(opList, station)
{   
	var myList = "#"+opList;
	var sc = "input[name=" + station  + "Code]";
	var s = "input[name=" + station + "]"
	$(myList).empty();
	$(sc).empty()
	var st = $(s).val();
	if(st == "" || st == undefined){
		return
	}

	for(var i = 1; i < sts.length; ++i)
	{
		currSt = sts[i].split('|')
//		alert(currSt)
		if(st != "" && currSt[1].match(st + ".*") != null)
		{
//			alert(currSt[1] +"&nbsp;" + currSt[2])
			$(sc).val(currSt[2]);
			var option="<option>"+ currSt[1] + "</option>";  
        	$(myList).append(option);
		}
	}
}

function search1(opList, station)
{   
	$("#mylist1").empty();
	$("input[name=endStationCode]").empty();
	var et = $("input[name=endStation]").val();
	if(et == "" || et == undefined){
		return
	}

	for(var i = 1; i < sts.length; ++i)
	{
		currSt = sts[i].split('|')
//		alert(currSt)
		if(et != "" && currSt[1].match(et + ".*") != null)
		{
//			alert(currSt[1] +"&nbsp;" + currSt[2])
			var option="<option>"+ currSt[1] + "</option>";  
			$("input[name=endStationCode]").val(currSt[2]);
        	$("#mylist1").append(option);
		}
	}
}
